package com.asia5b.a5mall.middleware.logic.viewmodel.member

import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.base.SimpleNetParams
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.base.ResultModel
import com.asia5b.a5mall.middleware.model.member.FootModel
import io.reactivex.functions.Consumer

class FootActivityVM :SimpleViewModel() {
  private var page = 1
  private var sumPage = 1000

    fun getDatas(refresh: Int) {
        if (refresh <= 1) {
            page = 1
            sumPage = 1000
        }
        if (page > sumPage) {
//            loadMvpView.dismissLoadingBar()
            loadingLiveData.value=1
            return
        }
        val observable = memberApi.getFootList(page)
        baseSubscribe(observable, SimpleNetParams(isShowLoading = refresh==0),Consumer { resultModel ->
            sumPage = resultModel.sumPage
            page=resultModel.page+1
//            providerView().getDatasResult(resultModel.data!!)
            getDatasResultLiveData.value=resultModel
        })
        //keytool -list -v -keystore c:/Users/Administrator/.android/debug.keystore -alias androiddebugkey
        //keytool -list -v -keystore /Users/zhangyuncai/Shop_Android/app/shop.jks -alias china
//678979f18182a16d2e5fb7412816f84a
//678979f18182a16d2e5fb7412816f84a
    }
    val getDatasResultLiveData=MutableLiveData<ResultModel<ArrayList<FootModel>>>()

    /**
     * @param ids 多个商品id
     * http://47.88.223.5:4001/members/history/682
     */
    fun deleteFoots(ids: ArrayList<Int>) {
        val goodsIds = TextUtils.join(",", ids)
        val observable = memberApi.deleteFootList(goodsIds)
        baseSubscribe(observable, Consumer { data ->
//            providerView().deleteFootsResult(ids)
            deleteFootsResultLiveData.value=ids
        })
    }
    val deleteFootsResultLiveData=MutableLiveData<ArrayList<Int>>()
}